import axios from 'axios';
import './date.format';
import md5 from 'md5';

export const util = {
    uuid: () => {
        function S4() {
            return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
        }

        return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
    },
    request: () => {
        const appKey = 'vRLPs9zI6d9ghlD7djEy0mQ0NEcVk7yL';
        const uuid = this.a.uuid();
        const nDate = new Date().format('Y-m-d H:i:s');
        const appToken = "u*MDDefxHDF^SgqEZTTN#Xf7O&VX5^qV9FyBqSAV9OO!5Lfdnk9PBcawYL^gUQs8oY8#foYYxtth$7C7qFmKSMApHCadKOhkG@V";
        let instance = axios.create({
            // baseURL: 'https://some-domain.com/api/',
            timeout: 5000,
            headers: {
                appKey: appKey,
                data: uuid,
                sysTime: nDate,
                sign: md5(uuid + nDate + appToken)
            }
        });
        return instance;
    }
}